<template>
  <div class="discount">
    <Title></Title>
    <div class="discount_box">
      <div class="inner">
        <div class="discount_tit">
          可供使用优惠券（{{discountdata.length}}张）
        </div>
        <div class="discount_list">
          <div class="discount_none" v-if="discountdata.length==0">
              没有优惠劵
          </div>
          <div class="discount_item" v-else v-for="(item,index) in discountdata" :key="index">
            <div class="discount_left">
              <div class="discount_price">
                ￥{{item.coupon_price}}
              </div>
              <div class="discount_condition">
                满{{item.coupon_floor}}可用
              </div>
              <div class="discount_use">
                <span>{{item.is_use==0?'当前':'不'}}可用</span>选中商品满足条件，下单可用
              </div>
            </div>
            <div class="discount_right ">
              <div class="discount_lright">
                <div class="discount_new">
                  【通用券】{{item.coupon_name}}
                </div>
                <div class="discount_app">
                  限商城内购物使用
                </div>
                <div class="discount_time">
                  {{item.coupon_start}}至{{item.coupon_stop}}
                </div>
              </div>
              <div class="discount_btn" @click="discountfn(item.coupon_id)">
                {{item.is_got==0?'去':'已'}}领取
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {discountapi,getdiscountapi} from "../../api/http.js"
  import Title from "../../components/title.vue"
  export default {
    name: 'discount',
    components: {
      Title
    },
    data(){
      return{
        discountdata:[]
      }
    },
    created() {
     this._discountfn()
    },
    methods:{
     async _discountfn(){
       const res = await discountapi()
       if(res.data.code==200){
          this.discountdata = res.data.data
       }else{
         this.$message(res.data.msg)
         this.discountdata=[]
       }
       console.log(res.data.data);
     },
     async discountfn(id){
       if(localStorage.getItem('user')==null) {
         this.$message("还没有登录，请先登录")
         await this.$router.push({path: "/login"})
         return false
       }
       console.log(id);
       var _that =this
        const res = await getdiscountapi({coupon_id:id})
        if(res.data.code==200){
         this.$message(res.data.msg)
        }else{
            this.$message(res.data.msg)
        }
        this._discountfn()
      }
    }
  }
</script>

<style lang="less">
  .discount {
    width: 100%;

    .discount_box {
      width: 100%;

      .inner {
        width: 1300px;
        margin: 0 auto;
        padding: 20px 100px;
        box-sizing: border-box;

        .discount_tit {
          width: 100%;
          height: 40px;
          line-height: 40px;
          font-size: 16px;
          color: white;
        }

        .discount_list {
          width: 100%;
          background: rgba(196, 196, 196, 0.11);
          border: 0.5px solid #CCCDCE;
          padding: 60px 50px;
          box-sizing: border-box;
          .discount_none{
            width: 100%;
            height: 200px;
            display: flex;
            justify-items: center;
            align-items: center;
            font-size: 14px;
          }
          .discount_item {
            width: 600px;
            height: 130px;
            padding-bottom: 50px;
            border-bottom: 1px solid white;
            //background: #FFFFFF;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-radius: 10px;
            margin-bottom: 20px;
            .discount_left::before {
              content: "";
              display: block;
              position: absolute;
              top: 50%;
              right: 0;
              width: 1px;
              height: 80px;
              margin-top: -40px;
              background-color: #CCCDCE;
            }

            .discount_left {
              position: relative;
              width: 50%;
              height: 100%;
              padding: 16px 0 0 8px;
              box-sizing: border-box;
              font-size: 14px;

              .discount_price {
                font-weight: 400;
                font-size: 24px;
                line-height: 34px;
                letter-spacing: -0.1em;
                color: #FF4444;
                margin-bottom: 10px;

              }

              .discount_condition {
                margin-bottom: 11px;
                color: #292929;
              }

              .discount_use {
                span {
                  padding: 5px;
                  color: #FF4444;
                  display: inline-block;
                  background: #FEF0F0;
                  border: 1px solid #FF4444;
                  border-radius: 5px;
                  margin-right: 10px;
                }
              }
            }

            .discount_right {
              width: 50%;
              height: 100%;
              padding: 10px 0 0 8px;
              box-sizing: border-box;
              font-size: 14px;
              display: flex;
              justify-content: space-between;
              align-items: center;

              .discount_lright {
                padding: 5px 0 20px 0;
                display: flex;
                justify-content: space-between;
                flex-direction: column;
                height: 100%;
                .discount_new {
                  font-weight: 500;
                  color: #292929;
                }

                .discount_app {
                  color: #FF4444;
                }

                .discount_time {

                  color: #292929
                }
              }

              .discount_btn {
                width: 83px;
                height: 32px;
                line-height: 32px;
                background: #FF4444;
                border-radius: 40px;
                text-align: center;
                color: #FFFFFF;
                margin-right: 15px;
              }
            }
          }
        }
      }
    }
  }
</style>
